<template>
  <div class="sqiye-page">
    <div class="sqiye-header">
      <CommonHeader
        type="黑"
        leftText="返回"
        :onLeft="dilogShow"
        :leftIcon="true"
        :title="dialogData.entityName"
      />
    </div>
    <div class="sqiye-list">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <div v-for="(item, index) in listData" :key="index">
          <div class="list-item">
            <div class="list-item-title">种子企业：{{ item.company }}</div>
            <div class="list-item-content">
              <div class="flex0">许可证号：</div>
              <div class="flexV flex1">
                <div
                  v-for="(licenceNo, index) in item.info.licenceNo"
                  :key="index"
                  class="licence-text"
                >
                  {{ licenceNo.name }}
                </div>
              </div>
            </div>
            <div class="list-item-content">
              <div class="flex0">品种名称：</div>
              <div class="flexV flex1">
                <van-grid :column-num="3" :border="false">
                  <van-grid-item
                    v-for="(seed, index) in item.info.seed"
                    :key="index"
                    :text="seed.name"
                    @click="itemClick(seed)"
                  >
                    <div class="seed-item">
                      <div class="seed-item-text">
                        {{ seed.name }}
                      </div>
                    </div>
                  </van-grid-item>
                </van-grid>
              </div>
            </div>
          </div>
        </div>
      </van-pull-refresh>
    </div>
  </div>
</template>
<script setup>
import uiUtil from "@/util/UiUtil.js";
import { data } from "jquery";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const refreshing = uiUtil.ref(false);
const listData = uiUtil.ref([]);
const props = defineProps({
  dilogShow: Function,
  dialogData: Object, //弹出框数据
});
uiUtil.onMounted(() => {
  console.log("uiUtil=", uiUtil);

  getDataList();
});

const onRefresh = () => {
  getDataList();
};

const getDataList = () => {
  const params = {
    searchEnterpriseName: props.dialogData.entityName,
  };
  uiUtil.http().getObj({
    url: uiUtil.urlPath.searchEnterpriseByEnterpriseName,
    data: params,
    start: () => {
      uiUtil.toastLoading();
    },
    succeed: (res) => {
      // loading.value = false;
      // debugger
      // console.log('1ucceed=', res)
      if (!res || !res.code || 200 != res.code) {
        uiUtil.toastFail(res.msg);
        return;
      }
      if (!res.data) {
        // 如果返回数据为空，表示已加载完成
        uiUtil.toastClose();
        return;
      }

      listData.value = res.data;
      uiUtil.toastClose();
    },
    failed: (res) => {
      // debugger
      console.log("failed=", res);
      uiUtil.toastFail("失败");
    },
    finish: () => {
      refreshing.value = false;
    },
  });
};

const itemClick = (item) => {
  console.log("wwwwww", item);

  router.push({
    path: uiUtil.routerPath.PinZhongXiangQingPage,
    query: { ...item },
  });
};
</script>

<style scoped lang="less">
.sqiye-page {
  height: 100vh;
  background-color: #f3f9f8;

  .sqiye-header {
    background-color: #fff;
  }

  .sqiye-list {
  }
  .list-item {
    margin-top: 12px;
    background-color: white;
    border-radius: 4px;
    box-sizing: border-box;
    margin-left: 15px;
    margin-right: 15px;
    margin-bottom: 10px;
    flex-shrink: 0;
  }

  .list-item-title {
    min-height: 40px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
    background-color: #f4fceb;
    border-radius: 4px 4px 0 0;
    box-sizing: border-box;
  }
  .list-item-content {
    font-size: 14px;
    padding: 12px 0 0 0;
    display: flex;
    flex-direction: row;
    margin-left: 10px;
  }
  .flexV {
    display: flex;
    flex-direction: column;
  }
  .flex0 {
    flex: 0 0 auto;
  }
  .flex1 {
    flex: 1 1 auto;
  }
  .licence-text {
    margin-bottom: 5px;
  }
  :deep(.van-grid-item__content) {
    padding: 0px;
    background-color: transparent;
  }
  .seed-item {
    display: flex;
    margin-bottom: 12px;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    text-align: center;
  }
  .seed-item-text {
    width: 100%;
    height: 100%;
    padding: 0px 2px;
    display: flex;
    margin: 0 12px 12px 0;
    background-color: #e7f9f4;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
}
</style>
